/**
 * 1. 這個跟 HttpSessionBindingListener 和 HttpSessionActivationListener 完全不同, 必需向應用程式註冊(web.xml, tag:listener)。<br>
 * 2. HttpSessionAttributeListener: 監控 session 屬性的生成、設定與刪除。<br>
 * 3. 再釐清一件事實, 這個 HttpSessionAttributeListener 是監控 session 的屬性, 而 HttpSessionBindingListener 是指物件被 binding 到 session。<br>
 * 二者主要的差別在於 HttpSessionBindingListener 必須由加入 session 的物件直接 implement, 但 implement HttpSessionAttributeListener<br>
 * 的類別並不直接參與整個 session 的運作。<br>
 * 所以選擇要 implement HttpSessionBindingListener 或 HttpSessionAttributeListener 是取決於應用程式本身。<br>
 */

package basic;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.e885.log.E885Logger;

/**
 * url:http://127.0.0.1:8080/JSPSessionAttributeListener/basic<br>
 * <br>
 * 1. 我們先將　String 物件( "eric.kao" ) 放到 session, 這時就會呼叫　HttpSessionAttributeListener.attributeAdded()。<br>
 * 2. 我們再用另一個　String 物件 ( "grace.lu" ) 取代之前的　"eric.kao", 這時就會呼叫 HttpSessionAttributeListener.attributeReplaced()。<br>
 * 3. 最後我們從 Session 移除 String 物件 ("grace.lu"), 這時就會呼叫 HttpSessionAttributeListener.attributeRemoved()。<br>
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class BasicServlet extends HttpServlet
{
	private static final long serialVersionUID = 2739294630128490723L;

	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		HttpSession session = request.getSession( true );

		E885Logger.testLog.debug( "=================== start set ==================" );
		session.setAttribute( "key", "eric.kao" );
		E885Logger.testLog.debug( "=================== end set ==================" );

		E885Logger.testLog.debug( "=================== start replace ==================" );
		session.setAttribute( "key", "grace.lu" );
		E885Logger.testLog.debug( "=================== end replace ==================" );

		E885Logger.testLog.debug( "=================== start remove ==================" );
		session.removeAttribute( "key" );
		E885Logger.testLog.debug( "=================== end remove ==================" );
	}

}
